import QtQuick 1.1
import com.nokia.meego 1.0

Dialog {
    id: helloDialog

    property Style platformStyle: QueryDialogStyle {}

    property string title: "Hello! :)"
    property string message:"It looks like you're running Dućanko for the first time. Nice!\n\nPush the button below to select the language of your choice!"

    property string acceptButtonText
    property string rejectButtonText
    property string languageAgainText

    property variant dialogLanguages

    signal accepted()

    content:
        Column{

        anchors.horizontalCenter: parent.horizontalCenter
        width: parent.width
        spacing: helloDialog.platformStyle.buttonsColumnSpacing

        Row{
            width: parent.width
            height: titleText.height*2

            Text{
                id: titleText

                text: title
                width: parent.width

                font.family: helloDialog.platformStyle.titleFontFamily
                font.pixelSize: helloDialog.platformStyle.titleFontPixelSize
                font.bold:  helloDialog.platformStyle.titleFontBold
                font.capitalization: helloDialog.platformStyle.titleFontCapitalization
                color: helloDialog.platformStyle.titleTextColor

                horizontalAlignment: Text.AlignHCenter
                verticalAlignment:   Text.AlignVCenter

            }
        }

        Row{
            width: parent.width

            spacing: 10

            Text{
                id: messageText

                text: message
                width: parent.width

                font.family: helloDialog.platformStyle.messageFontFamily
                font.pixelSize: helloDialog.platformStyle.messageFontPixelSize
                color: helloDialog.platformStyle.messageTextColor
                wrapMode: Text.WordWrap
                horizontalAlignment: Text.AlignHCenter

                verticalAlignment:   Text.AlignVCenter
            }
        }

        Button {
            id: chooseLanguage;
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Push me!"
            visible: text != ""
            __dialogButton: true
            platformStyle: ButtonStyle {inverted: true}

            onClicked: {

                var component = Qt.createComponent("MySelectionDialog.qml")
                dialogLanguages = component.createObject(helloDialog, {"model":modelLanguages})

                dialogLanguages.titleText = "Select language"
                dialogLanguages.selectedIndex = qmlHandler.getChosenLanguageIndex()

                dialogLanguages.accepted.connect(accept)

                dialogLanguages.open()
                console.log(helloDialog.platformStyle.messageFontFamily)
            }

            function accept(){
                qmlHandler.settings_SetLanguage(modelLanguages.get(dialogLanguages.selectedIndex).idJezika)
                chooseLanguage.text=qsTr("Very good!")

                menuPage.translate()

                chooseLanguage.text=""
                languageAgainText="Not my language :("

                message=qsTr("Do you want")+" Dućanko "+qsTr("to generate an example shopping list for you?")
                acceptButtonText=qsTr("Yes please!")
                rejectButtonText=qsTr("No thanks!")
                title=qsTr("Hello! :)")

                dialogLanguages.destroy()
            }
        }
    }

    buttons:
        //The following code is taken from QueryDialog.qml

        Item {
        id: buttonColFiller
        width: parent.width
        height: childrenRect.height

        anchors.top: parent.top

        Item {id: dummy; anchors.fill:  parent}

        Column {
            id: buttonCol
            anchors.top: parent.top
            anchors.topMargin: helloDialog.platformStyle.buttonTopMargin
            spacing: helloDialog.platformStyle.buttonsColumnSpacing

            height: (acceptButton.text  == "" ? 0 : acceptButton.height)
                    + (rejectButton.text == "" ? 0 : rejectButton.height)
                    + anchors.buttonTopMargin  + spacing

            anchors.horizontalCenter: parent.horizontalCenter

            Button {
                id: acceptButton
                text: acceptButtonText
                onClicked: {
                    accepted()
                }
                visible: text != ""
                __dialogButton: true
                platformStyle: ButtonStyle {inverted: true}
            }
            Button {
                id: rejectButton
                text: rejectButtonText
                onClicked: {
                    rejected()
                    helloDialog.destroy()
                }
                visible: text != ""
                __dialogButton: true
                platformStyle: ButtonStyle {inverted: true}
            }
            Button {
                id: languageAgainButton
                text: languageAgainText
                onClicked: {
                    acceptButtonText=""
                    rejectButtonText=""
                    languageAgainText=""
                    title="Hello! :)"
                    message="Push the button below (again) to select the language of your choice!"
                    chooseLanguage.text="Push me!"
                }
                visible: text != ""
                __dialogButton: true
                platformStyle: ButtonStyle {inverted: true}
            }
        }
    }
}
